// v2010.09.18

/*
Copyright (c) 2010 Ben Hendel-Doying

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

package game;

import java.awt.Color;

import resources.SoundLoader;

import world.Actor;
import world.Angel;
import world.Gate;
import world.Robes;
import world.Shield;
import world.Shop;
import world.Sword;
import world.World;
import gamesource.AnimatedPanel;

public class GamePanel extends AnimatedPanel
{
	private static final long serialVersionUID = -5141826290491097032L;

	private World world;
	private Actor player;

	private GameStatePlaying game;
	
	public GamePanel()
	{
		super(800, 600, 60);

		setBackground(Color.BLACK);
	}

	public void Start()
	{
		SoundLoader.get().getSound(1).Loop();
		
		NewGame();
	}

	public void NewGame()
	{
		player = new Angel(Actor.INTELLIGENCE_HUMAN);
		world = new World(player);

		player.EquipSword(new Sword(4));
		player.EquipRobes(new Robes(3));
		player.EquipShield(new Shield(2));
		player.PickUp(world.CreateMinorOneOff());
		player.PickUp(world.CreateMinorOneOff());

		player.Heal(player.GetMaxHP());

		game = new GameStatePlaying(this, world, player);
		ResumeGame();
	}

	public void Gate(Gate g)
	{
		ChangeState(new GameStateGate(this, player, g));
	}

	public void Shop(Shop s)
	{
		ChangeState(new GameStateShop(this, player, s));
	}

	public void ShopBuy(Shop s)
	{
		ChangeState(new GameStateShopBuying(this, player, s));
	}
	
	public void ConfirmQuit()
	{
		ChangeState(new GameStateQuitting(this));
	}

	public void Help()
	{
		ChangeState(new GameStateHelp(this));
	}

	public void Credits()
	{
		ChangeState(new GameStateCredits(this));
	}

	public void ResumeGame()
	{
		ChangeState(game);
	}

	public void ResumeGameAndStep()
	{
		ChangeState(game);
		game.Step();
	}

	public void Pray()
	{
		ChangeState(new GameStatePray(this, player));
	}

	public void PrayAttribute()
	{
		ChangeState(new GameStatePrayAttribute(this, player));
	}

	public void PraySkill()
	{
		ChangeState(new GameStatePraySkill(this, player));
	}

	public void Inventory()
	{
		ChangeState(new GameStateInventory(this, player));
	}

	public void CharacterStats()
	{
		ChangeState(new GameStatePlayerStats(this, player));
	}

	public void GameOver()
	{
		ChangeState(new GameStateGameOver(this, world, player));
	}
}
